﻿using IBLL;
using IDAL;
using Model;

namespace BLL
{
    public class Bll : IBll
    {
        public Bll(IDal<member> dal,IDal<memberType>dall)
        {
            Dal = dal;
            Dall = dall;
        }

        public IDal<member> Dal { get; }
        public IDal<memberType> Dall { get; }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>返回受影响行数</returns>
        public Task<int> Del(int id)
        {
            var list = Dal.Show().FirstOrDefault(a => a.memberId == id);
            list.memberState = true;
            return Dal.Update(list);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>返回受影响行数</returns>
        public Task<int> Dele(int dd)
        {
            var s = Dal.Show().FirstOrDefault(a=>a.memberId==dd);
            s.memberId = dd;
            return Dal.Delete(s);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="member">表名</param>
        /// <returns>返回受影响行数</returns>
        public Task<int> Tian(member member)
        {
            return Dal.Add(member);
        }
        /// <summary>
        /// 列表显示
        /// </summary>
        /// <returns>返回受影响函数</returns>
        public dynamic Xian()
        {
            var m=Dal.Show();
            var mt=Dall.Show();
            var list = from a in m
                       join b in mt on a.memberTypeId equals b.memberTypeId
                       select new 
                       {
                       a.memberId,
                       a.memberName,
                       a.memberAge,
                       a.memberSex,
                       a.memberState,
                       a.memberDate,
                       a.memberRq,
                       b.memberTypeId,
                       b.memberTypeName,
                       };
            return list;

        }
    }
}
